<?xml version="1.0" encoding="UTF-8"?>

<!--
    Document   : feedbackToPDF.xsl
    Created on : June 11, 2013, 8:58 AM
    Author     : Hoang
    Description:
        Purpose of transformation follows.
-->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:f-u="http://xml.netbeans.org/schema/feedback-user" exclude-result-prefixes="f-u">
    <xsl:output method="xml" indent="yes" encoding="UTF-8"/>


    <xsl:template match="/">
        <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">

            <fo:layout-master-set>

        <!-- layout information -->
                <fo:simple-page-master master-name="simple"
                  page-height="29.7cm"
                  page-width="21cm"
                  margin-top="1cm"
                  margin-bottom="0cm"
                  margin-left="1.5cm"
                  margin-right="1.5cm">
                    <fo:region-body margin-top="2cm"/>
                    <fo:region-before extent="2cm"/>
                    <fo:region-after extent="2cm"/>
                </fo:simple-page-master>
            </fo:layout-master-set>
        <!-- end: defines page layout -->

            <fo:page-sequence master-reference="simple">

      <!-- start fo:flow -->

                <fo:static-content flow-name="xsl-region-before">
                    <fo:block background-color="black" font-size="20pt" font-family="Tahoma"
        color="white" text-align="center">
                    Danh sách các feedback
                    </fo:block>
                </fo:static-content>

                <fo:flow flow-name="xsl-region-body">
                    <xsl:for-each select="//f-u:feedback">
                        <xsl:sort select="*[local-name()='sendDate']" order="descending"/>
                    <!-- 1 table la 1 feedback -->
                        <fo:table table-layout="fixed" width="100%" border-collapse="separate"
            font-family="Tahoma" border-width="0.5mm" border-style="solid"
            margin-bottom="7mm" padding-top="2mm" padding-bottom="2mm">
                            <fo:table-column column-width="10mm"/>
                            <fo:table-column column-width="30mm"/>
                            <fo:table-column column-width="110mm"/>
                            <fo:table-body>
                                <fo:table-row>
                                    <fo:table-cell>
                                        <fo:block></fo:block>
                                    </fo:table-cell>
                                    <fo:table-cell>
                                        <fo:block>Chủ đề</fo:block>
                                    </fo:table-cell>
                                    <fo:table-cell >
                                        <fo:block>
                                            <xsl:value-of select="f-u:title"/>
                                        </fo:block>
                                    </fo:table-cell>
                                </fo:table-row>

                                <fo:table-row>
                                    <fo:table-cell>
                                        <fo:block></fo:block>
                                    </fo:table-cell>
                                    <fo:table-cell >
                                        <fo:block>Người gửi</fo:block>
                                    </fo:table-cell>
                                    <fo:table-cell >
                                        <fo:block>
                                            <xsl:value-of select="f-u:username"/>
                                        </fo:block>
                                    </fo:table-cell>
                                </fo:table-row>

                                <fo:table-row>
                                    <fo:table-cell>
                                        <fo:block></fo:block>
                                    </fo:table-cell>
                                    <fo:table-cell >
                                        <fo:block>Nội dung</fo:block>
                                    </fo:table-cell>
                                    <fo:table-cell >
                                        <fo:block>
                                            <xsl:value-of select="f-u:feedbackContent"/>
                                        </fo:block>
                                    </fo:table-cell>
                                </fo:table-row>

                                <fo:table-row>
                                    <fo:table-cell>
                                        <fo:block></fo:block>
                                    </fo:table-cell>
                                    <fo:table-cell >
                                        <fo:block>Ngày gửi</fo:block>
                                    </fo:table-cell>
                                    <fo:table-cell >
                                        <fo:block>
                                            <xsl:call-template name="formatDate">
                                                <xsl:with-param name="dateIn">
                                                    <xsl:value-of select='f-u:sendDate'/>
                                                </xsl:with-param>
                                            </xsl:call-template>
                                        </fo:block>
                                    </fo:table-cell>
                                </fo:table-row>
                            </fo:table-body>
                        </fo:table>
                    </xsl:for-each>

                </fo:flow> <!-- closes the flow element-->
            </fo:page-sequence> <!-- closes the page-sequence -->
        </fo:root>

    </xsl:template>

<!-- Dung de format ngay thang -->
    <xsl:template name="formatDate">

        <xsl:param name="dateIn" />
        <xsl:variable name="year" select="substring($dateIn, 1, 4)" />
        <xsl:variable name="month" select="substring($dateIn, 6, 2)" />
        <xsl:variable name="date" select="substring($dateIn, 9, 2)" />
        <xsl:variable name="time" select="substring($dateIn, 12, 8)" />
        <xsl:value-of select="concat('Ngày ',$date, '/', $month, '/', $year,' lúc ',$time)" />

    </xsl:template>

</xsl:stylesheet>
